#include "FiveWin.ch"

static aDDEs := {}

static nLastMsg

//----------------------------------------------------------------------------//

CLASS TDde

   DATA   nService, nTopic, nItem
   DATA   bAction
   DATA   oWndServer

   METHOD New( cService, cTopic, cItem, bAction ) CONSTRUCTOR
   METHOD Activate()
   METHOD Execute( cCommand )
   METHOD DeActivate() VIRTUAL
   METHOD Release()    VIRTUAL

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cService, cTopic, cItem, bAction ) CLASS TDde

   ::nService = GlobalAddAtom( cService )
   ::nTopic   = GlobalAddAtom( cTopic )
   ::nItem    = GlobalAddAtom( cItem )
   ::bAction  = bAction

   AAdd( aDDEs, Self )

return

//----------------------------------------------------------------------------//

METHOD Activate() CLASS TDde

   nLastMsg = WM_DDE_INITIATE

   SendMessage( -1, WM_DDE_INITIATE, GetWndApp(),;
                nMakeLong( ::nService, ::nTopic ) )

return

//----------------------------------------------------------------------------//

METHOD Execute( cCommand ) CLASS TDde

   nLastMsg = WM_DDE_EXECUTE

   ::oWndServer:PostMsg( WM_DDE_EXECUTE, GetWndApp(),;
                         DdeCommand( cCommand ) )
return

//----------------------------------------------------------------------------//

function DdeAck( hWndServer, nLParam )

   local nService, nTopic
   local nDde, oDde

   do case
      case nLastMsg == WM_DDE_INITIATE
           nService = nLoWord( nLParam )
           ATail( aDDEs ):oWndServer = TWindow()
           ATail( aDDEs ):oWndServer:hWnd = hWndServer

      case nLastMsg == WM_DDE_EXECUTE
           DdeGetCommand( nLParam )
   endcase

return

//----------------------------------------------------------------------------//
